require 'socket'

puts "RoboRealm mock server... replying with moves in a circle from -1.0 to 1.0, rrbox = 10 to all UDP requests on 7070."

# Bind on 7070
server = UDPSocket.new
server.bind("127.0.0.1",7070)

loop do 
  # Receive anything
  msg, sender = server.recvfrom(100)
  host = sender[3] # remote ipaddr
  puts "Received #{msg} from #{host}"

  k = 2*Math::PI*(Time.now.to_f%10)/10.0
  x = Math.sin(k)
  y = Math.cos(k)
  
  # Send response to 7071
  UDPSocket.open.send("#{x},#{y},10", 0, host, 7071)
end
